package br.com.bb.robot.view;

import br.com.bb.robot.controller.FileIOController;
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public final class FileChooser extends JFrame {

    public FileChooser() {
        super("© Banco do Brasil");
    }

    public String createFileChooser() throws FileNotFoundException {
        Integer result;
        FileIOController fileIO = new FileIOController();
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        result = fileChooser.showOpenDialog(this);
        if (result == JFileChooser.CANCEL_OPTION) {
            return null;
        }
        File file = fileChooser.getSelectedFile();
        if ((file.getName().equals("")) || file == null) {
            JOptionPane.showMessageDialog(this, "Nome inválido", "© Banco do Brasil", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        fileIO.setFile(file);
        fileIO.loadFile();
        return fileIO.getText();
    }
}
